package com.sky.mapper;

import com.sky.dto.DataQueryDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderMapper {

    // @Insert("insert into orders(number, status, user_id, address_book_id, order_time, checkout_time, pay_method,\n" +
    //         "                   pay_status, amount, remark, phone, address, user_name, consignee, cancel_reason,\n" +
    //         "                   rejection_reason, cancel_time, estimated_delivery_time, delivery_status, delivery_time,\n" +
    //         "                   pack_amount, tableware_number, tableware_status)values (#{number},#{status},#{userId},#{addressBookId},#{orderTime},#{checkoutTime},#{payMethod},#{payStatus},#{amount},#{remark},#{phone},#{address},#{userName},#{consignee},#{cancelReason},#{ejectionReason},#{cancelTime},#{estimatedDeliveryTime},#{deliveryStatus},#{deliveryTime},#{packAmount},#{tablewareNumber},#{tablewareStatus})")
    void addOrder(Orders orders);

    void addOrderDetails(List<OrderDetail> orderDetailList);

    @Select("select * from orders where number = #{orderNumber}")
    Orders getById(String orderNumber);

    // 修改订单状态
    void update(Orders orders);

    // 查询历史订单
    List<Orders> historyOrders(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from order_detail where order_id = #{orderId}")
    List<OrderDetail> getDetaliById(Long id);

    @Select("select id, number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, remark, phone, address, user_name, consignee, cancel_reason, rejection_reason, cancel_time, estimated_delivery_time, delivery_status, delivery_time, pack_amount, tableware_number, tableware_status from orders where status = 5 and order_time like concat(#{date},'%')")
    List<Orders> activeOrder(String date);

    @Select("select COUNT(*) from orders where status = 5 and order_time like concat(#{date},'%')")
    int activeOrderCount(String date);
    @Select("select COUNT(*) from orders where status = 5 and date (order_time)>=#{begin} and date (order_time)<=#{end}")
    int activeOrderCount30(DataQueryDTO dataQueryDTO);

    @Select("select COUNT(*) from orders where order_time like concat(#{date},'%')")
    int allOrder(String date);
}
